<template>
	<view class="page">
		<navbar backIconName="arrow-left" title="入企任务" :titleStyle="titleStyle"></navbar>
		<scroll-view class="scroll-view_H" scroll-y="true">
			<view :style="{height:statusHeight+'px'}"></view>
			<view class="company-info">
				<text style="font-size: 26rpx;color: #999;">入企人员信息</text>
				<view class="staff-card">
					<view class="left">
						<view class="top">
							<text
								style="font-size: 30rpx;color: #323232;font-weight: bold;margin-right: 20rpx;">{{sysUser.nickName || '-'}}</text>
							<text
								style="font-size: 26rpx;background-color: #FFE657;padding: 4rpx 8rpx;color: #fff;border-radius: 6rpx;">执法人员</text>
						</view>
						<text style="font-size: 28rpx;color: #666;">{{sysUser.deptName || '-'}}</text>
					</view>
					<!-- <text
						style="font-size: 26rpx;color: #1169DB; font-weight: bold;padding: 0px 30rpx;height: 90rpx;line-height: 90rpx; background-color: #DAEAFF;border-radius: 10rpx;">身份信息</text> -->

				</view>
			</view>
			<view class="company-info">
				<text style="font-size: 26rpx;color: #999;">企业信息</text>
				<view class="staff-card">
					<view class="left">
						<view class="top">
							<text
								style="font-size: 30rpx;color: #323232;font-weight: bold;margin-right: 20rpx;">{{companyInfo.companyName || '-'}}</text>
						</view>
						<text
							style="font-size: 28rpx;color: #666;">统一社会信用代码：{{companyInfo.socialCreditNumber || '-'}}</text>
					</view>

				</view>
			</view>
			<view class="inCompany-task">
				<text style="font-size: 26rpx;color: #999;">入企任务</text>

				<view v-if="taskList.length > 0">
					<view class="task-item normal" v-for="(item,index) in taskList" :key="index"
						@click="selectTaskCard(item,index)">
						<view class="left">
							<view class="top">
								<text
									style="font-size: 26rpx;color: #666;flex: 1;">{{item.enterpriseTaskNo || '-'}}</text>
								<text
									class="status">{{item.status == '0'?'待入企':item.status == '1'?'已入企':item.status == '2'?'待企业评价':item.status == '3'?'已评价':''}}</text>
							</view>
							<text
								style="font-size: 28rpx;color: #666;margin: 20rpx 0rpx;font-weight: bold;">{{item.taskName || '-'}}</text>
							<text
								style="font-size: 26rpx;color: #666;margin-bottom: 14rpx;">入企类型：{{item.taskTypeName}}</text>
							<!-- <text
								style="font-size: 26rpx;color: #666;margin-bottom: 14rpx;">计划入企日期：{{item.enterprisePlanDate}}</text> -->
							<text
								style="font-size: 26rpx;color: #666;margin-bottom: 14rpx;">计划入企人数：{{item.enterpriseTaskPersonnelList.length}}</text>
						</view>

					</view>
				</view>
				<!-- 无入企任务 -->
				<view v-else style="padding: 60rpx 0rpx;">
					<u-empty mode="data" text="暂无入企任务" textSize="14" iconSize="100"></u-empty>
				</view>
			</view>
			<!-- <view class="submit-content">
				<view v-if="taskList.length > 0">
					<u-button :throttleTime="1000" type="primary" text="确认入企" @click="submitInCompany"></u-button>
				</view>
				<view>
					<u-button type="primary" :throttleTime="1000" :plain="true" text="临时入企"
						@click="toTemporary"></u-button>
				</view>
			</view> -->
		</scroll-view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		getTaskList,
		sureEnter,
	} from '@/api/pagesMall'
	import {
		showConfirm,
	} from "@/utils/common.js"
	import store from '@/store'
	let App = getApp();
	export default {
		components: {},
		data() {
			return {
				statusHeight: 44 + App.globalData.statusBarHeight,
				titleStyle: {
					color: "#ffffff",
					fontWeight: "bold",
					fontSize: "18px"
				},
				defaultTask: 0,
				taskList: [],
				socialCreditNumber: "",
				userId: "",
				userInfo: store.state.user.USER_INFO,
				companyInfo: {
					companyName: '',
					socialCreditNumber: '',
				},
				currentCompanyInfo: store.state.user.COMPANY_INFO,
				sysUser: null,
			};
		},
		onLoad(options) {
			this.userId = options.userId
			this.getTask()
		},
		methods: {
			/* 获取入企任务 */
			getTask() {
				getTaskList({
					socialCreditNumber: this.currentCompanyInfo.socialCreditNumber,
					userId: this.userId
				}).then(res => {
					if (!res.data.socialCreditNumber) {
						this.$refs.uToast.show({
							type: "default",
							title: "默认主题",
							message: "未获取到执法人员信息",
							duration: 2000,
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 2000)
					}
					this.sysUser = res.data.sysUser
					this.companyInfo.companyName = res.data.companyName || ''
					this.companyInfo.socialCreditNumber = res.data.socialCreditNumber || ''
					this.taskList = (res.data.enterpriseTaskRespVos && res.data.enterpriseTaskRespVos.length > 0) ?
						res.data.enterpriseTaskRespVos : []
				})
			},
			/* 确认入企 */
			submitInCompany() {
				if (this.taskList.length == 0) {
					return uni.$u.toast('未获取到入企任务')
				}
				let taskSelect = this.taskList[this.defaultTask]
				showConfirm('确认要提交入企？').then(res => {
					if (res.confirm) {
						sureEnter({
							enterpriseTaskNo: taskSelect.enterpriseTaskNo,
							userId: this.userId
						}).then(res => {
							uni.$u.toast('入企成功！')
							this.getTask()
							setTimeout(() => {
								uni.navigateTo({
									url: '/pages-mine/pages/enterCpRecord/detail?enterpriseTaskNo=' +
										taskSelect.enterpriseTaskNo
								});
							}, 1000)
						})
					}
				});
			},
			/* 选择任务 */
			selectTaskCard(item, index) {
				this.defaultTask = index
			},
			/* 临时入企 */
			toTemporary() {
				uni.navigateTo({
					url: '/pages-mall/pages/toTemporary/index?socialCreditNumber=' + this.socialCreditNumber
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.page {
		position: relative;
	}

	.submit-content {
		padding: 30rpx;
		height: 200rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}

	.scroll-view_H {
		width: 100%;
		height: 100%;

		.inCompany-task {
			display: flex;
			flex-direction: column;
			padding: 30rpx;

			.active {
				border: 1px solid #1169DB;
			}

			.normal {
				border: 1px solid transparent;
			}


			.task-item {
				display: flex;
				align-items: center;
				padding: 20rpx;
				margin-top: 20rpx;
				background-color: #fff;
				border-radius: 12rpx;
				box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.15);



				.left {
					flex: 1;
					display: flex;
					flex-direction: column;

					.top {
						display: flex;
						align-items: center;
						padding-bottom: 20rpx;
						border-bottom: 1px solid #D8D8D8;

						.status {
							font-size: 24rpx;
							color: #323232;
							font-weight: bold;
							background-color: #1169DB;
							color: #fff;
							padding: 4rpx 10rpx;
							border-radius: 10rpx;
						}
					}
				}
			}
		}

		.company-info {
			display: flex;
			flex-direction: column;
			padding: 30rpx;

			.staff-card {
				display: flex;
				align-items: center;
				padding: 20rpx;
				margin-top: 20rpx;
				background-color: #fff;
				border-radius: 12rpx;
				box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.15);

				.left {
					flex: 1;
					display: flex;
					flex-direction: column;

					.top {
						margin-bottom: 30rpx;
					}
				}
			}
		}



	}
</style>